const app = getApp()
import {
  imageUrl
} from "../../utils/imageutil.js"
Page({
  data: {
    imageUrl: imageUrl,
    userInfo: wx.getStorageSync('userInfo'),
    titleBarHeight: app.globalData.titleBarHeight,
    titleBarUsableWidth: app.globalData.titleBarUsableWidth,
    nodes: '',
    tel: '',
    callstore: '',
    address: '',
    navlistcurr: 1,
    facade: '', //门头照
    navlist: [{
      title: '服务项目',
      id: 1
    }, {
      title: '服务评价',
      id: 2
    }, {
      title: '服务人员',
      id: 3
    }, {
      title: '公司简介',
      id: 4
    }],

    type_arr: [{
      title: '全部',
      type: ''
    }, {
      title: '好评',
      type: 1
    }, {
      title: '中评',
      type: 2
    }, {
      title: '差评',
      type: 3
    }],
    type_curr: '',

    recommendPage: 1,
    recommendFlag: true,
    recommendList: [],

    housekeeperListPage: 1,
    housekeeperListType: '',
    housekeeperListby: '',
    housekeeperListFlag: true,
    housekeeperList: [],

    commentsList: [],
    commentsPage: 1,
    commentsFlag: true,

    store_info: null,
    store_id: '',
    name: ''
  },
  onLoad: function (options) {
    this.setData({
      store_id: options.store_id,
      userInfo: wx.getStorageSync('userInfo'),
    })
    this.getRecommend();
    this.getPageAssessList();
    this.gethousekeeperList();
    this.StoreInfo()
  },
  StoreInfo() {
    app.globalData.post({
      data: {
        do: 'StoreInfo',
        store_id: this.data.store_id,
      }
    }).then(res => {
      this.setData({
        store_info: res.data.store,
        nodes: res.data.store.details,
        tel: res.data.store.tel,
        callstore: res.data.store.callstore,
        address: res.data.store.address,
        logo: res.data.store.logo
      })
    })
  },
  changenavlistcurr(e) {
    this.setData({
      navlistcurr: e.currentTarget.dataset.id
    })
  },
  change_type_arr(e) {
    this.setData({
      type_curr: e.currentTarget.dataset.type,
      commentsList: [],
      commentsPage: 1,
      commentsFlag: true,
    })
    this.getPageAssessList()
  },
  onPullDownRefresh() {
    this.setData({
      navlistcurr: 1,
      recommendPage: 1,
      recommendFlag: true,
      recommendList: [],

      commentsList: [],
      commentsPage: 1,
      commentsFlag: true,
      type_curr: '',

      housekeeperListPage: 1,
      name: '',
      housekeeperListFlag: true,
      housekeeperList: [],

    })
    this.getRecommend();
  },
  onReachBottom() {
    if (this.data.navlistcurr == 1) {
      if (this.data.recommendFlag) {
        this.getRecommend();
      }
    } else if (this.data.navlistcurr == 2) {
      if (this.data.commentsPage) {
        this.getPageAssessList()
      }
    } else if (this.data.navlistcurr == 3) {
      if (this.data.housekeeperListFlag) {
        this.gethousekeeperList()
      }
    }
  },
  getRecommend() {
    if (!this.data.recommendFlag) {
      return
    }
    this.setData({
      recommendFlag: false
    })
    app.globalData.post({
      data: {
        do: 'DishesListNew',
        store_id: this.data.store_id,
        page: this.data.recommendPage,
        pagesize: 10
      }
    }).then(res => {
      wx.stopPullDownRefresh();
      if (res.data.data.length == 0) {
        this.setData({
          recommendFlag: false
        })
      } else {
        let arr = this.data.recommendList.concat(res.data.data);
        this.setData({
          recommendList: arr,
          recommendPage: this.data.recommendPage + 1,
          recommendFlag: true
        })
      }
    })
  },
  getPageAssessList() {
    if (!this.data.commentsFlag) {
      return
    }
    app.globalData.post({
      data: {
        do: 'AssessList',
        store_id: this.data.store_id,
        page: this.data.commentsPage,
        pagesize: 10,
        type: this.data.type_curr,
      }
    }).then(res => {
      wx.stopPullDownRefresh();
      if (res.data.assess.length == 0) {
        this.setData({
          commentsFlag: false
        })
      } else {
        let arr = this.data.commentsList.concat(res.data.assess);
        this.setData({
          commentsList: arr,
          commentsPage: this.data.commentsPage + 1
        })
      }
    })
  },
  gethousekeeperList() {
    if (!this.data.housekeeperListFlag) {
      return
    }
    app.globalData.post({
      data: {
        do: 'housekeeperList',
        uid: wx.getStorageSync('userInfo').id,
        page: this.data.housekeeperListPage,
        by: this.data.housekeeperListby,
        pagesize: 10,
        type: this.data.housekeeperListType,
        store_id: this.data.store_id,
        name: this.data.name
      }
    }).then(res => {
      wx.stopPullDownRefresh();
      if (res.data.data.length == 0) {
        this.setData({
          housekeeperListFlag: false
        })
      } else {
        let arr = this.data.housekeeperList.concat(res.data.data);
        this.setData({
          housekeeperList: arr,
          housekeeperListPage: this.data.housekeeperListPage + 1
        })
      }
    })
  },
  to_projects(e) {
    wx.navigateTo({
      url: '../all/make?good_id=' + e.currentTarget.dataset.id,
    })
  },
  to_aunt(e) {
    wx.navigateTo({
      url: '../aunt/index?uid=' + e.currentTarget.dataset.id,
    })
  },
  back_next() {
    getApp().to_back()
  },
  tel() { //拨打电话
    getApp().phoneCall(this.data.callstore)
  },
  changekeywords(e) { //搜索家政员
    this.setData({
      name: e.detail.value,
      housekeeperListPage: 1,
      housekeeperListFlag: true,
      housekeeperList: [],
    })
    this.gethousekeeperList()
  },

  openmap() {
    getApp().openmap(this.data.store_info.latitude, this.data.store_info.longitude)
  },
})